<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <input type="text" id="username" />
        <input type="radio" id="sexOne"  name="sex" value="男"/>男
        <input type="radio" id="sexTwo" checked name="sex" value="女"/>女
        <input type="text" id="age" />
        <button id="add">添加</button>
    </div>
    <br/>
    <table cellspacing="0" border="1" width="600px" >
        <thead>
            <tr>
                <td width="20%">
                    <input type="checkbox" class="selectAll" >全选
                    <input type="checkbox" class="selectOther" >反选
                </td>
                <td>姓名</td>
                <td>性别</td>
                <td>年龄</td>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <script>
        var str ='';
        document.querySelector("#add").onclick = function () {
            var name = document.querySelector("#username").value;
            var gender = document.querySelector("input[name='sex']:checked").value;
            var age = document.querySelector("#age").value;
            var tab=document.querySelector("tbody");
                str += `<tr>
                <td> <input type="checkbox" class="selectChild" name="ddd"></td>   
                <td>${name}</td>
                <td>${gender}</td>
                <td>${age}</td>
                </tr>`; 
            tab.innerHTML = str;
        }
        document.querySelector(".selectAll").onclick=function(){
            var selectChild=document.querySelectorAll(".selectChild")
            if( document.querySelector(".selectAll").checked){
                for(var i=0;i<selectChild.length;i++){
                selectChild[i].checked=true;
            }
            }else{
                for(var i=0;i<selectChild.length;i++){
                selectChild[i].checked=false;
            }
            }            
        }
        document.querySelector(".selectOther").onclick=function(){
            var selectChild=document.querySelectorAll(".selectChild")
                for(var i=0;i<selectChild.length;i++){
                selectChild[i].checked=!selectChild[i].checked;
            }}
    </script>
</body>
</html>